{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "broken-peeing",
   "metadata": {},
   "source": [
    "# 02. Absorbing Object\n",
    "A simple example using the AbsorbingObject"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cathedral-package",
   "metadata": {},
   "source": [
    "## Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "broken-logan",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import fdtd\n",
    "fdtd.set_backend(\"numpy\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ready-necklace",
   "metadata": {},
   "source": [
    "## Constants"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "tight-disposal",
   "metadata": {},
   "outputs": [],
   "source": [
    "WAVELENGTH = 1550e-9\n",
    "SPEED_LIGHT: float = 299_792_458.0  # [m/s] speed of light"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "expired-sugar",
   "metadata": {},
   "source": [
    "## Grid setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "rural-context",
   "metadata": {},
   "outputs": [],
   "source": [
    "# create FDTD Grid\n",
    "grid = fdtd.Grid(\n",
    "    (1.5e-5, 1.5e-5, 1),  # 2D grid\n",
    "    grid_spacing=0.1 * WAVELENGTH,\n",
    "    permittivity=2.5,  # same as object\n",
    ")\n",
    "\n",
    "# sources\n",
    "grid[15, :] = fdtd.LineSource(period=WAVELENGTH / SPEED_LIGHT, name=\"source\")\n",
    "\n",
    "# detectors\n",
    "grid[-15, :, 0] = fdtd.LineDetector(name=\"detector\")\n",
    "\n",
    "# x boundaries\n",
    "# grid[0, :, :] = fdtd.PeriodicBoundary(name=\"xbounds\")\n",
    "grid[0:10, :, :] = fdtd.PML(name=\"pml_xlow\")\n",
    "grid[-10:, :, :] = fdtd.PML(name=\"pml_xhigh\")\n",
    "\n",
    "# y boundaries\n",
    "# grid[:, 0, :] = fdtd.PeriodicBoundary(name=\"ybounds\")\n",
    "grid[:, 0:10, :] = fdtd.PML(name=\"pml_ylow\")\n",
    "grid[:, -10:, :] = fdtd.PML(name=\"pml_yhigh\")\n",
    "\n",
    "# The absorbing object fills the whole grid\n",
    "grid[10:-10, 10:-10, :] = fdtd.AbsorbingObject(\n",
    "    permittivity=2.5, conductivity=1e-6, name=\"absorbin_object\"\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "discrete-bulgaria",
   "metadata": {},
   "source": [
    "## Simulation without absorption:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "advisory-delivery",
   "metadata": {},
   "outputs": [],
   "source": [
    "grid.run(250, progress_bar=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "assured-chamber",
   "metadata": {},
   "source": [
    "## Visualization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "according-redhead",
   "metadata": {},
   "outputs": [],
   "source": [
    "grid.visualize(z=0)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
